import {
  INCREASE,
  DECREASE
} from '../constants/count_const'
import store from '../store'

export const increaseAction = (data) => {
  return {
    type: INCREASE,
    data
  }
}

export const decreaseAction = (data) => {
  return {
    type: DECREASE,
    data
  }
}

export const whenOddIncreaseAction = (data) => {
  const {
    count
  } = store.getState()
  return () => {
    if (count % 2 !== 0) {
      store.dispatch(increaseAction(data))
    }
  }
}

export const delayIncreaseAction = (data) => {
  return () => {
    setTimeout(() => {
      store.dispatch(increaseAction(data))
    }, 2000)
  }
}